package com.blb.educourseservice.controller;

import com.blb.common.util.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试MQ
 */
@RestController
public class MQDemoController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    public String sendMessage(String type,String message){
        //发送消息给交换机 参数1 交换机 参数2 键 参数3 内容
        if("save".equals(type)){
            rabbitTemplate.convertAndSend(RabbitMQConfig.COURSE_EXCHANGE,RabbitMQConfig.KEY_COURSE_SAVE,message);
        }else if("remove".equals(type)){
            rabbitTemplate.convertAndSend(RabbitMQConfig.COURSE_EXCHANGE,RabbitMQConfig.KEY_COURSE_REMOVE,message);
        }
        return "ok";
    }
}
